<?php

namespace app\api\controller;

use app\api\service\CommodityService;
use app\api\service\LoginService;
use app\BaseController;
use app\common\model\Commodity;
use app\common\service\CommonOrderService;
use app\common\service\CommonTYService;
use app\Response;
use think\facade\Cache;
use think\facade\Db;
use think\facade\Request;

class Test extends BaseController{

    public function test1(){
        var_dump(Cache::get('data'));
    }
    /**
     * 版本号存储
    */
    public function writeVersion(){
        $version = Request::param("version");
        $file_name ="/usr/local/nginx/html/order_assistant/public/uploads/api/writeVersion.txt";
        $fz = file_exists($file_name);
        $file_pointer = fopen($file_name,"w");
        fwrite($file_pointer,$version);
        fclose($file_pointer);
        return Response::wrapData();
    }

    public function orderPostWx(){
        $order = \app\common\model\Order::dataInfo(["id"=>487]);
        $user = \app\common\model\User::userInfo(["uid"=>$order["uid"]]);
        if (!empty($order)){
            $order = $order->toArray();
        }
        $order["tracking_no"] = "433859991697606";
        $order["openid"] = $user["open_id"];
        $res = CommonOrderService::orderDeliveryInfoSync($order);
        var_dump($res);
    }
    /**
     * 版本号获取
     */
    public function getVersion(){
        $file_name ="/usr/local/nginx/html/order_assistant/public/uploads/api/writeVersion.txt";
        $fz = file_exists($file_name);
        $version = "";
        if($fz){
            $fp=fopen($file_name,'r');
            while(!feof($fp))
            {
                $version=fgets($fp,4096);
            }
            fclose($fp);
        }
        return Response::wrapData($version);
    }


    public function postTest(){
        $post_num = Request::param("post_num");
        if(!empty($post_num)){
            $res = CommonTYService::TyLogistics($post_num);
            return Response::wrapData($res);
        }else{
            return "";
        }
    }


    public function gerSqlResault(){

        $sql ="";
        $res = Db::query($sql);
        return Response::wrapData($res);
    }
}